import { defineStore } from 'pinia'

// pinia定义数据对象
export const loginInfoStore = defineStore('loginInfo', {
  state: () => {
    return {
      dep: '',
      dep_name: '',
      token: '',
      token: '',
      token: '',
      username: '',
      code: '',
      user_type: '',
      lessees_ype: '',
      lessees_name: '',
      lessees_id: '',
      user_id: '',
      // 激活菜单
      menuActive: ''
    }
  },
  getters: {},
  actions: {
    idUpdate(val) {
      // console.log(999)
      this.id = val
    }, usernameUpdate(val) {
      // console.log(999)
      this.username = val
    }, tokenUpdate(val) {
      // console.log(999)
      this.token = val
    }
  },
  // 配置数据刷新是否缓存
  persist: {
    enabled: true,
    strategies: [
      {
        // 缓存的键名
        key: 'logininfo',
        storage: sessionStorage,
        // 需要缓存的数据
        paths: ['token', 'username', 'user_id', 'menuActive', 'lessees_name','lessees_id', 'lessees_ype', 'user_type']
      },
    ]
  }


})


// 顶部导航菜单
export const tabsBarStore = defineStore('tabsBar', {
  state: () => {
    return {
      data: [
        {
          router: '/home',
          title: '工作台',
          activate: true
        }
      ]
    }
  },
  getters: {},
  actions: {

  },
  // 配置数据刷新是否缓存
  persist: {
    enabled: true,
    strategies: [
      {
        // 缓存的键名
        key: 'tabsBar',
        storage: sessionStorage,
        // 需要缓存的数据
        paths: ['data']
      },
    ]
  }


})

// 组件加载动画
export const loadingStore = defineStore('loading', {
  state: () => {
    return {
      loading: false,
      text: '数据请求中...',
    }
  },
  getters: {},
  actions: {
    idUpdate(val) {
      // console.log(999)
      this.id = val
    }, usernameUpdate(val) {
      // console.log(999)
      this.username = val
    }, tokenUpdate(val) {
      // console.log(999)
      this.token = val
    }
  }
})

// 系统权限
export const permissionStore = defineStore('permission', {
  state: () => {
    return {
      data: {}
    }
  },
  getters: {},
  actions: {
    idUpdate(val) {
      // console.log(999)
      this.id = val
    }, usernameUpdate(val) {
      // console.log(999)
      this.username = val
    }, tokenUpdate(val) {
      // console.log(999)
      this.token = val
    }
  },
  // 配置数据刷新是否缓存
  persist: {
    enabled: true,
    strategies: [
      {
        // 缓存的键名
        key: 'permission',
        storage: sessionStorage,
        // 需要缓存的数据
        paths: ['data']
      },
    ]
  }


})